# Contributor: Paweł Tomak <pawel@tomak.eu>
# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=pike
pkgver=8.0.1940
pkgrel=0
pkgdesc="Pike programming language"
url="https://pike.lysator.liu.se/"
# ppc64le: hangs while building modules in src/post_modules
arch="all !ppc64le"
license="GPL-2.0-or-later"
options="!check" # there are no tests for those packages
depends="readline"
makedepends="
	bzip2-dev
	freeglut-dev
	gdbm-dev
	giflib-dev
	giflib-utils
	gmp-dev
	gtk+2.0-dev
	librsvg-dev
	libsm-dev
	mesa-gl
	nettle
	nettle-dev
	nettle-utils
	pcre-dev
	sdl12-compat-dev
	sdl_mixer-dev
	sqlite-dev
	sqlite-libs
	zlib-dev
	"
subpackages="$pkgname-doc $pkgname-full::noarch"
source="$pkgname-$pkgver.tar.gz::https://pike.lysator.liu.se/pub/pike/alpha/$pkgver/Pike-v$pkgver.tar.gz"
builddir="$srcdir/Pike-v$pkgver"

_full_deps="$pkgname=$pkgver-r$pkgrel $pkgname-doc=$pkgver-r$pkgrel"
for _name in bzip2 gdbm gl gtk image pcre sdl svg sqlite
do
	subpackages="$subpackages $pkgname-$_name"
	_full_deps="$_full_deps $pkgname-$_name=$pkgver-r$pkgrel"
done

build() {
	export MAKEFLAGS="$MAKEFLAGS -j1"
	make CONFIGUREARGS=" \
		--prefix=/usr \
		--disable-make_conf \
		--disable-noopty-retry \
		--without-cdebug \
		--without-bundles \
		--without-ssleay \
		--with-gmp \
		--with-crypt \
		--with-bignums \
		--without-rtldebug \
		--with-Bz2 \
		--without-fftw \
		--without-_Ffmpeg \
		--with-gdbm \
		--without-GTK1 \
		--with-GTK2 \
		--with-jpeglib \
		--without-Kerberos \
		--without-msql \
		--without-mysql \
		--without-Odbc \
		--without-oracle \
		--with-GL \
		--with-GLUT \
		--with-_Regexp_PCRE \
		--without-libpdf \
		--without-sass \
		--with-sane \
		--with-SDL \
		--disable-sdltest \
		--with-SDL_Mixer \
		--with-svg \
		--with-tifflib \
		--without-freetype \
		--without-vcdiff \
		--with-_Image_WebP \
		--with-zlib"
	PATH="$builddir/bin:$PATH" make doc
}

package() {
	make INSTALLARGS="--traditional" buildroot="$pkgdir" install

	rm -Rf "$pkgdir"/usr/doc
	mkdir -vp "$pkgdir"/usr/share/doc/
	mv -v	"$builddir"/refdoc/traditional_manual \
		"$pkgdir"/usr/share/doc/$pkgname
}

bzip2() {
	pkgdesc="$pkgdesc (BZip2 support)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/pike/modules/*Bz2.*
}

gdbm() {
	pkgdesc="$pkgdesc (GDBM support)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/pike/modules/*Gdbm.*
}

gl() {
	pkgdesc="$pkgdesc (OpenGL/GLUT support)"
	depends="$pkgname=$pkgver-r$pkgrel freeglut libsm"

	amove usr/lib/pike/modules/*GL*
}

gtk() {
	pkgdesc="$pkgdesc (GTK2 support)"
	depends="$pkgname-image=$pkgver-r$pkgrel"

	amove usr/lib/pike/modules/*GTK2*
	amove usr/lib/pike/modules/*Gnome2*
	amove usr/lib/pike/modules/Tools.pmod/PV.pike
}

image() {
	pkgdesc="$pkgdesc (image handling modules)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/pike/?.?/modules/Image.pmod
	amove usr/lib/pike/modules/Image.so
	amove usr/lib/pike/modules/*Image_[!S]*.so
	amove usr/lib/pike/modules/*Image*.pmod
	amove usr/lib/pike/modules/Graphics.pmod
	amove usr/lib/pike/modules/Colors.pmod
	amove usr/lib/pike/modules/Protocols.pmod/X.pmod/XImage.pmod
}

pcre() {
	pkgdesc="$pkgdesc (PCRE support)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/pike/modules/*Regexp_PCRE.*
}

sdl() {
	pkgdesc="$pkgdesc (SDL support)"
	depends="$pkgname-image=$pkgver-r$pkgrel"

	amove usr/lib/pike/modules/*SDL.*
}

svg() {
	pkgdesc="$pkgdesc (SVG support)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/pike/modules/_Image_SVG.so
}

sqlite() {
	pkgdesc="$pkgdesc (SQLite support)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/pike/modules/*SQLite.*
	amove usr/lib/pike/modules/Sql.pmod/sqlite*
}

full() {
	pkgdesc="Meta package for $pkgdesc"
	depends="$_full_deps"

	mkdir -vp "$subpkgdir"
}

sha512sums="
981e57d17fb6567f2c6d94cec8acacd6150312d7038501c1e9abb8185b4d131384ee0f2bac967bfd20c29c2456f56a0949db5b88853f824de368f7930d8762cd  pike-8.0.1940.tar.gz
"
